package com.hotel.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hotel.entity.Refund;
import com.hotel.mapper.RefundMapper;
import com.hotel.service.RefundService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hotel.vo.RefundVO;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lin
 * @since 2022-06-20
 */
@Service
public class RefundServiceImp extends ServiceImpl<RefundMapper, Refund> implements RefundService {

    @Resource
    private RefundMapper mapper;

    @Override
    public IPage<Refund> getRefundList(String refundNo,String nickName, String status, String createTime, Integer current, Integer size) {
        List<Refund> refundList = mapper.getRefundList(refundNo,nickName, status, createTime);
        List pageList = new ArrayList<>();
        int curIdx = current > 1 ? (current - 1) * size : 0;
        for (int i = 0; i < size && curIdx + i < refundList.size(); i++) {
            pageList.add(refundList.get(curIdx + i));
        }
        IPage page = new Page<>(current, size);
        page.setRecords(pageList);
        page.setTotal(refundList.size());
        return page;
    }

    @Override
    public RefundVO getRefundDetails(String refundNo) {
        return mapper.getRefundDetails(refundNo);
    }
}
